package com.chenjt.activiti.utils;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2022/5/12 20:04
 */

public class StartBpmnUtils {


    public static void main(String[] args) {


//        initTable();
        deployProcessDefinition("224-inner(揭阳市储备粮食有限公司).bpmn20.xml","揭阳市储备粮食有限公司");


    }

    /**
     * 部署流程定义
     */
    public static void deployProcessDefinition(String classPathResource,String processName){

        //1.创建ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        //2.得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();

        //3.进行部署
        Deployment deployment = repositoryService.createDeployment()
//                .addClasspathResource("bpmn/224-inner.bpmn20.xml")  //添加bpmn资源
                .addClasspathResource("bpmn/" + classPathResource)  //添加bpmn资源
//                .addClasspathResource("bpmn/holiday.png")
//                .name("揭阳市储备粮食有限公司")
                .name(processName)
                .deploy();

        //4.输出部署的一些信息
        System.out.println(deployment.getName());
        System.out.println(deployment.getId());//id的值是数据库自动生成的



    }


    /**
     * 初始化数据库表
     */
    private static void initTable(){



        //条件：1.activiti配置文件名称：activiti.cfg.xml   2.bean的id="processEngineConfiguration"
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);

        // HistoryService historyService = processEngine.getHistoryService();


        //1.创建ProcessEngineConfiguration对象  第一个参数:配置文件名称  第二个参数是processEngineConfiguration的bean的id
//        ProcessEngineConfiguration configuration = ProcessEngineConfiguration
//                .createProcessEngineConfigurationFromResource("activiti.cfg.xml","processEngineConfiguration");
//        //2.创建ProcesEngine对象
//        ProcessEngine processEngine = configuration.buildProcessEngine();
//
//        //3.输出processEngine对象
//        System.out.println(processEngine);



    }



}
